package com.tan.androidtest.anim;

import android.util.Log;
import android.view.MotionEvent;
import android.widget.TextView;

import com.tan.androidtest.R;
import com.tan.androidtest.anim.property.MyProcessView;
import com.tan.androidtest.base.BaseActivity;

/**
 * 联合touch使用anim
 */

public class TestAnimWithTouchEventActivity extends BaseActivity {

    private MyProcessView mMyProcessView;

    @Override
    public int initLayoutId() {
        return R.layout.activity_test_anim_with_touch_event_layout;
    }

    @Override
    public void initTitle(TextView tv_bar_left, TextView tv_bar_title, TextView tv_bar_right) {
        tv_bar_title.setText("测试自定义view和Touch等事件");
    }

    @Override
    public void initView() {
        mMyProcessView = findViewById(R.id.my_process_view);
        mMyProcessView.setProcess(0);
    }

    @Override
    public void initData() {
        /*ObjectAnimator animator = ObjectAnimator.ofFloat(mMyProcessView, "process", 0, 80);
        animator.setRepeatMode(ValueAnimator.REVERSE);
        animator.setRepeatCount(ValueAnimator.INFINITE);
        animator.setDuration(2000);
        animator.start();*/
    }

    float downX = 0;//点下的点
    float downY = 0;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                downX = event.getX();
                downY = event.getY();
                //Log.i("==--", "downY = " + downY);
                break;
            }
            case MotionEvent.ACTION_MOVE: {
                //计算横向移动
                float hen = Math.abs(event.getX() - downX);
                //计算间距
                float process = Math.abs((event.getY() - downY) / 5);
                Log.i("==--", "process = " + process);
                if (process >= 100) {
                    process = 100;
                }

                mMyProcessView.setProcess(process);

                break;
            }
            case MotionEvent.ACTION_UP: {

                break;
            }
        }
        return super.onTouchEvent(event);
    }
}
